package com.woniuxy.dr_mall.shiro;

import com.woniuxy.dr_mall.mapper.DrPermMapper;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.LinkedHashMap;
import java.util.Map;


public class PermMapFactoryBean implements FactoryBean<Map<String, String>> {

    @Autowired
    private DrPermMapper permMapper;

    @Override
    public Map<String, String> getObject() throws Exception {
        Map<String, String> maps = new LinkedHashMap<>();
        maps.put("/dr_mall/drUser/login", "anon");
        maps.put("/dr_mall/drUser/back_end-login", "anon");
        maps.put("/dr_mall/drSpecPrice/get_skus", "anon");

        maps.put("/index/detail/**","anon");
        maps.put("/dr_mall/drProducts/collect/**","authc");
        maps.put("/index/lists", "anon");//进到分页查询界面
        maps.put("/dr_mall/drProducts/viewProducts", "anon");//首页查看人气最高
//        maps.put("/dr_mall/drProducts/viewProducts","anon");//首页查看女生最爱
//        maps.put("/dr_mall/drProducts/viewProducts","anon");//首页查看爆款热卖
        maps.put("/login.html", "anon");//注册
        maps.put("/reg.html", "anon");//登录
        maps.put("/question.html", "anon");
        maps.put("/dr_mall/drProducts/add_product/**","jwt");
        //个人中心
        maps.put("/dr_mall/drOrders/userIdSelectOrders","jwt");
        maps.put("dr_mall/drOrders/deleteOrder","jwt");
        maps.put("/dr_mall/drUser/maintain","jwt");
        maps.put("/dr_mall/drUser/selectUserFavoriteImformation","jwt");
        maps.put("/dr_mall/drUserFavorite/deleteFavorite","jwt");
       //maps.put("/dr_mall/drUser/updateUserImformation","anon");
      // maps.put("/dr_mall/drUser/updateUserImformation","anon");


        maps.put("/index/detail/**", "anon");//商品详情
        maps.put("/", "anon");
        maps.put("/css/**", "anon");
        maps.put("/js/**", "anon");
        maps.put("/images/**", "anon");
        maps.put("/layer/**", "anon");
//        maps.put("/dr_mall/drMenu/list", "jwt");



//        maps.put("/dr_mall/**","jwt");
//        maps.put("/perm/get_manager_perms", "jwt");
//        maps.put("/role/**", "jwt,myperms[role_list]");
//        maps.put("/manager/**", "jwt");
//        maps.put("/perm/**", "jwt");


        permMapper.getPerms().forEach(p -> {
                    maps.put(p.getLink(), "authc,perms[" + p.getCode() + "]");
                }
        );
        maps.put("/index/logout", "logout");
//        maps.put("/**", "authc");
        return maps;
    }
    @Override
    public Class<?> getObjectType() {
        return Map.class;
    }

}